package com.atguigu.tingshu.order.config;

import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author atguigu-mqx
 * @ClassName CanelOrderMqConfig
 * @description: TODO
 * @date 2024年10月10日
 * @version: 1.0
 */
@Configuration
public class CancelOrderMqConfig {

    //  配置交换机
    @Bean
    public CustomExchange cancelOrderExchange(){
        //  封装一个map集合
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("x-delayed-type", "direct");
        //  返回对象;
        return new CustomExchange(MqConst.EXCHANGE_CANCEL_ORDER, "x-delayed-message", true, false,map);
    }
    //  配置队列
    @Bean
    public Queue delayQueue(){
        //  创建对象
        return new Queue(MqConst.QUEUE_CANCEL_ORDER, true, false, false);
    }
    //  配置路由键绑定
    @Bean
    public Binding bindingDelayQueue(){
        //  绑定队列到交换机
        return BindingBuilder.bind(delayQueue()).to(cancelOrderExchange()).with(MqConst.ROUTING_CANCEL_ORDER).noargs();
    }
}
